package response

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

type Result struct {
	Errcode int `json:"errcode"`;
	Errmsg string `json:"errmsg"`;
	Data map[string]interface{} `json:"data"`;
}

// Success 请求成功函数
func Success(context *gin.Context,errcode int,errmsg string,data map[string]interface{}){
	result := &map[string]interface{}{"errcode": errcode, "errmsg":errmsg,"data": data}
	context.JSON(http.StatusOK,result)
}

// Fail 请求失败函数
func Fail(context *gin.Context,errcode int,errmsg string,httpcode ... int ){

	result := &map[string]interface{}{"errcode": errcode, "errmsg":errmsg,}
	if len(httpcode)==0{
		context.JSON(http.StatusForbidden,result)
	}else {
		context.JSON(httpcode[0],result)
	}

}